package com.codingchili.social;

import com.codingchili.social.configuration.SocialContext;
import com.codingchili.social.controller.OnlineHandler;
import com.codingchili.social.controller.SocialHandler;
import io.vertx.core.Promise;

import com.codingchili.core.context.CoreContext;
import com.codingchili.core.listener.CoreService;

/**
 * @author Robin Duda
 * <p>
 * Service for social features such as party and friend lists.
 */
public class Service implements CoreService {
    private CoreContext core;

    @Override
    public void init(CoreContext core) {
        this.core = core;
    }

    @Override
    public void start(Promise<Void> start) {
        var social = new SocialContext(core);
        core.handler(() -> new SocialHandler(social))
                .compose((a) -> core.handler(() -> new OnlineHandler(social)))
                .onComplete((done) -> {
                    if (done.succeeded()) {
                        start.complete();
                    } else {
                        start.fail(done.cause());
                    }
                });
    }
}
